import axios from 'axios'
import { showFailToast,showLoadingToast } from 'vant'

// const instance = axios.create({
//   baseURL:'http://localhost:3000',
//   timeout:1000000,
// })

axios.defaults.baseURL = 'http://localhost:3000'
axios.defaults.headers.post['Content-Type'] = 'application/json'

axios.interceptors.request.use((res) =>{
  showLoadingToast({message:'请求中',forbidClick:true})
  console.log(res,'请求头')
  return res
},(err) =>{
  console.log(err)
  showFailToast('请求出错，请重试')
  return Promise.reject(err)
})

axios.interceptors.response.use((res) => {
  console.log(res,'响应头');
  if (res.status !== 200) {
    showFailToast(res.data.msg)
  }
  else {
    if (res.data.code !== '1') {
      return res
    }
    return res.data
  }
})

export default axios